package com.yuan.springcloud.user.controller.open;

import com.alibaba.fastjson.JSON;
import com.yuan.springcloud.user.bean.open.OpenResult;
import com.yuan.springcloud.user.bean.po.UserPO;
import com.yuan.springcloud.user.bean.vo.UserQueryVO;
import com.yuan.springcloud.user.bean.vo.UserVO;
import com.yuan.springcloud.user.service.UserService;
import com.yuan.springcloud.user.utils.Transform;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author YouYuan
 * @date 2022/11/21 2:15
 */
@Api(value = "用户开放接口",tags = "用户开放Api")
@RequestMapping("/open/user")
@RestController
@Slf4j
public class UserOpenApi {
    @Autowired
    UserService userService;

    @Autowired
    Transform transform;

    @PostMapping("/query")
    @ApiOperation(value = "查询用户列表")
    public OpenResult<List<UserVO>> queryUser(@RequestBody UserQueryVO queryParam) {
        log.info("UserOpenApi query args:{}", JSON.toJSONString(queryParam));
        List<UserPO> userList = userService.queryUserList(queryParam);
        return OpenResult.success(transform.user.po2vo(userList));
    }
}
